package com.qf.controller;

import cn.hutool.core.lang.tree.Tree;
import com.qf.entity.ProductCategory;
import com.qf.service.ProductCategoryService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- 万物归集  不随你我 ---
 * <p>
 * 快捷短语
 * main ==  public static void main(String[] args);
 * sout ==  System.out.println();
 *
 * @author shuhan
 * @date 2025/4/29
 * @desc
 */
@RestController
@RequestMapping("/product/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    @GetMapping("/list")
    public R list(){
        List<Tree<String>> list = productCategoryService.list();
        return R.ok(list);

    }

   @GetMapping("/delete")
    public R delete(Integer id){
        productCategoryService.delete(id);
        return R.ok();
   }

   @PostMapping("/addProductCategory")
    public R add(@RequestBody ProductCategory productCategory){
        productCategoryService.add(productCategory);
        return R.ok();
   }

   @GetMapping("/findNameById")
    public R findNameById(Integer id){
        String name = productCategoryService.findNameById(id);
        return R.ok(name);
   }

   @PostMapping("/updateProductCategory")
    public R update(@RequestBody ProductCategory productCategory){
        productCategoryService.update(productCategory);
        return R.ok();
   }
}
